<template>
	<view class="content">
		<view class="none_msg"  v-if="InfoList.length==0">
			<image src="../../static/image/offerxq_img_k@2x.png" mode=""></image>
			<view class="none_title">暂无信息</view>
		</view>
		<view class="list_box" v-else>
			<view class="list_item" v-for="(item,index) in InfoList" :key="index">
				<view class="list_left">
					<view class="list_title">{{item.name}}</view>
					<view class="list_info">{{item.answer_num}}已做  |  答题时长 {{item.answer_time}}分钟</view>
				</view>
				<view class="list_right"  @click="CreatOrder(item.id,item.is_buy)"><image src="../../static/image/mkst_ico_bj@2x.png"></image></view>
			</view>
		</view>
	</view>
</template>

<script>
	import {questionbank,ordercreate} from "@/api/data.js"
	export default {
		data() {
			return {
				classid:'',
				typeid:'',
				InfoList:'',
				ordernum:'',
				price:'',
				orderSn:'',
				page:1,
				limit:10
			}
		},
		onLoad(option) {
			this.classid=option.classid
			this.typeid=option.typeid
			this.getTestList(this.page,this.limit)
		},
		onShow() {
			this.getTestList(this.page,this.limit)
		},
		onPullDownRefresh() {
			//console.log('refresh');
			this.getTestList(1,this.limit);
			setTimeout(function () {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onReachBottom(){
			this.page = this.page+1;
			this.getTestList(this.page,this.limit);
			console.log(111)
		},
		methods: {
			goDet(id){
				
			},
			getTestList(page,limit){
				var obj = {
					type:this.typeid,
					class_id:this.classid,
					page:page,
					pageSize:limit
				};
				questionbank(obj).then(res => {
					if (res.code == 1) {
						if(page!=1){
							if(res.data){
								this.InfoList = this.InfoList.concat(res.data)
							}
						}else{
							this.InfoList = res.data
						}
					}
				});
			},
			// 创建试题订单
			CreatOrder(id,is_buy){
				if(is_buy==1){
					uni.navigateTo({
						url:'testDetL?id='+id
					})
				}else{
					var obj = {
						type:2,
						q_id:id
					};
					ordercreate(obj).then(res => {
						if (res.code == 1) {
							this.ordernum=res.data.id
							this.price=res.data.price
							this.orderSn=res.data.order_sn
								uni.navigateTo({
									url:'../payment/payment?oid='+this.ordernum+'&price='+this.price+'&id='+id+'&orderSn='+this.orderSn
								})
						}
					});
				}
			}
		
		}
	}
</script>

<style>
	.content{
		width: 100%;
		height: 100%;
	}
	.list_box{
		width: 100%;
		height: auto;
		background-color: #FFFFFF;
		margin-top: 20rpx;
		padding: 0 30rpx;
	}
	.list_item{
		width: 100%;
		height: 170rpx;
		display: flex;
		justify-content: space-between;
		align-items: flex-start;
		border-bottom: 1rpx solid #F5F5F5;
	}
	.list_right{
		height: 100%;
		display: flex;
		align-items: flex-end;
		padding-bottom: 30rpx;
	}
	.list_right image{
		width: 29rpx;
		height: 26rpx;
	}
	.list_left{
		height: 100%;
		width: 85%;
		padding: 25rpx 0;
		display: flex;
		align-items: flex-start;
		justify-content: space-between;
		flex-direction: column;
	}
	.list_title{
		width: 80%;
		font-size: 28rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #333333;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box; /*将对象作为弹性伸缩盒子模型显示。*/
		-webkit-line-clamp: 2; /*设置需要显示的行数*/
		-webkit-box-orient: vertical; /*设置伸缩盒子的子元素排列方式(从上到下垂直排列)*/
	}
	.list_info{
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #999999;
		margin-top: 10rpx;
	}
	.none_msg {
		width: 100%;
		height: auto;
		display: flex;
		justify-content: center;
		align-items: center;
		flex-direction: column;
		margin-top: 300rpx;
	}
	
	.none_msg image {
		width: 354rpx;
		height: 253rpx;
	}
	
	.none_title {
		font-size: 26rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #666666;
		margin-top: 40rpx;
	}
</style>
